using System.Collections;
using UnityEngine;

public class tk2dUIDemo5Controller : tk2dUIBaseDemoController
{
	public tk2dUILayout prefabItem;

	public tk2dUIScrollableArea manualScrollableArea;

	public tk2dUILayout lastListItem;

	public tk2dUIScrollableArea autoScrollableArea;

	private void CustomizeListObject(Transform contentRoot)
	{
		string[] array = new string[10]
		{
			"Ba",
			"Po",
			"Re",
			"Zu",
			"Meh",
			"Ra'",
			"B'k",
			"Adam",
			"Ben",
			"George"
		};
		string[] array2 = new string[28]
		{
			"Hoopler",
			"Hysleria",
			"Yeinydd",
			"Nekmit",
			"Novanoid",
			"Toog1t",
			"Yboiveth",
			"Resaix",
			"Voquev",
			"Yimello",
			"Oleald",
			"Digikiki",
			"Nocobot",
			"Morath",
			"Toximble",
			"Rodrup",
			"Chillaid",
			"Brewtine",
			"Surogou",
			"Winooze",
			"Hendassa",
			"Ekcle",
			"Noelind",
			"Animepolis",
			"Tupress",
			"Jeren",
			"Yoffa",
			"Acaer"
		};
		string text = array[Random.Range(0, array.Length)] + " " + array2[Random.Range(0, array2.Length)];
		Color color = new Color32((byte)Random.Range(192, 255), (byte)Random.Range(192, 255), (byte)Random.Range(192, 255), byte.MaxValue);
		contentRoot.Find("Name").GetComponent<tk2dTextMesh>().text = text;
		contentRoot.Find("HP").GetComponent<tk2dTextMesh>().text = "HP: " + Random.Range(100, 512).ToString();
		contentRoot.Find("MP").GetComponent<tk2dTextMesh>().text = "MP: " + (Random.Range(2, 40) * 10).ToString();
		contentRoot.Find("Portrait").GetComponent<tk2dBaseSprite>().color = color;
	}

	private void Start()
	{
		prefabItem.transform.parent = null;
		DoSetActive(prefabItem.transform, state: false);
		float num = 0f;
		Vector3 vector = prefabItem.GetMaxBounds() - prefabItem.GetMinBounds();
		float x = vector.x;
		for (int i = 0; i < 10; i++)
		{
			tk2dUILayout tk2dUILayout = Object.Instantiate(prefabItem);
			tk2dUILayout.transform.parent = manualScrollableArea.contentContainer.transform;
			tk2dUILayout.transform.localPosition = new Vector3(num, 0f, 0f);
			DoSetActive(tk2dUILayout.transform, state: true);
			CustomizeListObject(tk2dUILayout.transform);
			num += x;
		}
		Transform transform = lastListItem.transform;
		float x2 = num;
		Vector3 localPosition = lastListItem.transform.localPosition;
		transform.localPosition = new Vector3(x2, localPosition.y, 0f);
		float num2 = num;
		Vector3 vector2 = lastListItem.GetMaxBounds() - lastListItem.GetMinBounds();
		num = num2 + vector2.x;
		manualScrollableArea.ContentLength = num;
		for (int j = 0; j < 10; j++)
		{
			tk2dUILayout tk2dUILayout2 = Object.Instantiate(prefabItem);
			autoScrollableArea.ContentLayoutContainer.AddLayoutAtIndex(tk2dUILayout2, tk2dUILayoutItem.FixedSizeLayoutItem(), autoScrollableArea.ContentLayoutContainer.ItemCount - 1);
			DoSetActive(tk2dUILayout2.transform, state: true);
			CustomizeListObject(tk2dUILayout2.transform);
		}
	}

	private IEnumerator AddSomeItemsManual()
	{
		Vector3 localPosition = lastListItem.transform.localPosition;
		float x = localPosition.x;
		Vector3 vector = prefabItem.GetMaxBounds() - prefabItem.GetMinBounds();
		float w = vector.x;
		int numToAdd = Random.Range(1, 5);
		for (int i = 0; i < numToAdd; i++)
		{
			tk2dUILayout layout = Object.Instantiate(prefabItem);
			layout.transform.parent = manualScrollableArea.contentContainer.transform;
			layout.transform.localPosition = new Vector3(x, 0f, 0f);
			DoSetActive(layout.transform, state: true);
			CustomizeListObject(layout.transform);
			x += w;
			Transform transform = lastListItem.transform;
			float x2 = x;
			Vector3 localPosition2 = lastListItem.transform.localPosition;
			transform.localPosition = new Vector3(x2, localPosition2.y, 0f);
			tk2dUIScrollableArea tk2dUIScrollableArea = manualScrollableArea;
			float num = x;
			Vector3 vector2 = lastListItem.GetMaxBounds() - lastListItem.GetMinBounds();
			tk2dUIScrollableArea.ContentLength = num + vector2.x;
			yield return new WaitForSeconds(0.2f);
		}
	}

	private IEnumerator AddSomeItemsAuto()
	{
		int numToAdd = Random.Range(1, 5);
		for (int i = 0; i < numToAdd; i++)
		{
			tk2dUILayout layout = Object.Instantiate(prefabItem);
			autoScrollableArea.ContentLayoutContainer.AddLayoutAtIndex(layout, tk2dUILayoutItem.FixedSizeLayoutItem(), autoScrollableArea.ContentLayoutContainer.ItemCount - 1);
			DoSetActive(layout.transform, state: true);
			CustomizeListObject(layout.transform);
			yield return new WaitForSeconds(0.2f);
		}
	}
}
